<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>下单</title>
</head>
<body>
<button id="buy" value="{$ids}">购买成功</button>
</body>
</html>

<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<script>
    $("#buy").click(function (){
       console.log("buy success\n");
       $.post("{:url('/buy')}",{"data":this.value},function (res){
           console.log(res);
           if(res.status==='0'){
               alert("购买结果\r\n"+res.msg+"\r\n"+res.err);
               location.href="{:url('/')}"
           }else {
               alert("接口请求失败");
           }
       },"json");
    });
</script>